import { getAppList, saveData } from '../../api/urls';

// initial state
const state = () => ({
    all: []
});
// getters
const getters = {};
// actions
const actions = {
    getAllProducts({ commit }) {
        // 调用ajax接口
        getAppList().then((res) => {
            commit('setProducts', res);
        });
    },
    addProductToCart({ commit }, params) {
        console.log(params);
        // 调用ajax接口
        saveData(params).then(() => {
            commit('saveSucess');
        });
    }
};

// mutations
const mutations = {
    setProducts(state, res) {
        state.all = res;
    },
    saveSucess() {
        console.log('save成功');
    }
};

export default {
    namespaced: true,
    state,
    getters,
    actions,
    mutations
};
